from django.db import models
from django.contrib.auth.models import User
from tagging.fields import TagField
from datetime import datetime


class Bookmark(models.Model):
  '''
    Clone of del.icio.us style bookmarks
  '''

  title = models.CharField(max_length=200)
  user = models.ForeignKey(User)
  description = models.TextField(blank=True)
  url = models.URLField(verify_exists=False, max_length=255)
  tags = TagField()

  created_date = models.DateTimeField(default=datetime.now())
  modified_date = models.DateTimeField(default=datetime.now()) 

  def __unicode__(self):
    return self.title

  def get_absolute_url(self):
    return '/bookmarks/%s/' % self.user

  def get_search_url(self):
    return '/bookmarks/%s/search/' % self.user

  class Admin:
    list_display = ('title', 'url', 'user')
    search_fields = ('title', 'description','tags','user')
    date_hierarchy = 'modified_date'

  class Meta:
    ordering = ('-modified_date',)
    unique_together = [("user", "url")]


